Skip to content

fix(github-backup): paginate queue polling (#3476) - #3484

Merged
dezren39 merged 3 commits into
mainfrom
queue/5428-3476-queue-pagination
Nov 4, 2026
Merged

dezren39 merged 3 commits into
mainfrom
queue/5428-3476-queue-pagination

Conversation

@dezren39

@dezren39 dezren39 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

GET /queue?cursor=… -> one KV page + cursor/list_complete
                       ↓
drain_queue follows all pages -> existing fetch/ack policy
  • Worker forwards the optional cursor and exposes KV pagination metadata.
  • Drainer collects every page before applying the existing ack policy; incomplete or repeated cursors fail closed.
  • Add Worker route coverage and the 500 retained failures + later healthy event regression. Failed events remain unacked.

Fixes #3476

Evidence

Merge Danger

Door: two-way

Blast Radius: narrow

The change affects only the authenticated queue polling response and its drainer. Existing event acknowledgement policy and the 500-item per-page limit are preserved.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Improvements

    • Queue retrieval now supports pagination, allowing large queues to be processed across multiple pages.
    • Queue acknowledgements are sent in batches, including when processing large numbers of events.
  • Bug Fixes

    • Added safeguards for incomplete or invalid pagination responses to prevent unreliable queue processing.

@dezren39
dezren39 requested a review from a team as a code owner November 1, 2026 10:14
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T07:24:31.565927Z ae02486 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The Worker now exposes queue pagination metadata. The drainer follows pages before applying its acknowledgement policy and sends acknowledgements in batches of up to 500 IDs. Tests cover pagination, retained failed events, acknowledgement batches, and unauthenticated requests.

Changes: Queue pagination and draining

Layer / File(s) Summary
Worker queue pagination
infra/github-backup/worker/src/index.js, infra/github-backup/worker/test/index.test.mjs
The /queue endpoint passes an optional cursor to KV listing and returns events with a cursor and list_complete status. Tests check pagination responses and that unauthenticated requests do not call KV list.
Drainer pagination and acknowledgment batches
infra/github-backup/bin/drain_queue.py, infra/github-backup/tests/test_drain_queue.py
The drainer follows pages and validates event data and pagination cursors. It acknowledges IDs in batches of 500. Tests check that a healthy event after 500 failing events is processed and that 1,200 events produce three acknowledgement requests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Drainer as drain_queue.py
  participant Worker as GET /queue
  participant KV as GHB_EVENTS
  Drainer->>Worker: Request queue page with cursor
  Worker->>KV: List events with prefix, limit, and cursor
  KV-->>Worker: Return events and pagination metadata
  Worker-->>Drainer: Return events, cursor, and list_complete
  Drainer->>Worker: Request another page when listing is incomplete
  Drainer->>Worker: Acknowledge IDs in batches of up to 500
Loading
Merge Risk: Minimal · up to ae024

The pagination and bounded acknowledgment changes have no established blocking defect. Comparing exact acknowledged IDs would strengthen the batching regression test.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 21a4e83fa4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +87 to +89
events.extend(page_events)
if page.get("list_complete", True):
return events

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Batch acknowledgements after collecting multiple queue pages

When a backlog contains more than 1,000 ackable events, collecting every page makes main() send all their IDs in a single /queue/ack request. That Worker handler performs one awaited KV delete per ID, but Cloudflare limits each invocation to 1,000 KV operations, so the request fails after partially deleting the batch and the drainer exits with an error. Previously, the 500-event polling limit kept acknowledgements below this ceiling. Split acknowledgements into bounded requests so multi-page backlogs can drain successfully.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: acknowledgements are now sent through ack_events(), which batches ids at ACK_BATCH_SIZE = 500 per /queue/ack request — well under the Worker's 1,000-KV-operation invocation limit — so multi-page backlogs drain completely instead of failing mid-batch. Regression test in test_drain_queue.py case 15: 1,200 ackable events produce 3 bounded ack requests with every event acked (63/63 checks pass).

@dezren39

dezren39 commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

🤖 Agent note · parked (task 8248, lane code-e)

Parking task 8248: the Codex gate blocks merge of PR #3484 — one undispositioned P2 finding, reverified fresh 2026-11-04 (no replies on the thread):

  • drain_queue.py (comment 4435215151) — batch acknowledgements after collecting multiple queue pages: when a backlog contains more than 1,000 ackable events, acks must be batched within KV limits.

Resume condition: fix that finding on PR #3484 (or reply-disposition it with reasoning), then merge when the PR is mergeable and all findings are dispositioned.

developing-today[bot] added 2 commits November 4, 2026 01:20
# Conflicts:
#	infra/github-backup/bin/drain_queue.py
#	infra/github-backup/tests/test_drain_queue.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

github-backup(queue): retained failed events starve polling — /queue returns only the first 500 events with no pagination

1 participant